﻿using BW.IBLL;
using BW.Model;
using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BW.BLL
{
    public class shipuBLL : IshipuBLL
    {
        public shipuBLL(IbaseDAL<shipuModel> dal,IbaseDAL<fenleiModel> dal2)
        {
            Dal = dal;
            Dal2 = dal2;
        }

        public IbaseDAL<shipuModel> Dal { get; }
        public IbaseDAL<fenleiModel> Dal2 { get; }

        public Task<int> tinajia(shipuModel m)
        {
            return Dal.AddAsync(m); 
        }

        public dynamic xianshi(string? name, int Fid)
        {
            var shipu = Dal.GetAll();
            var fenlei=Dal2.GetAll();

            var rph = from a in shipu
                      join b in fenlei
                      on a.Fid equals b.Fid
                      select new
                      {
                          a.Fid,
                          a.Id,
                          a.img,
                          a.Name,
                          b.Fname
                      };
            if (!string.IsNullOrEmpty(name))
            {
                rph=rph.Where(x => x.Name.Contains(name));
            }
            if(Fid>0)
            {
                rph = rph.Where(x => x.Fid==Fid);
            }

            return rph.ToList();
        }
    }
}
